/*  mudmap - A tool to create and organize user side maps for MUD games
 *  Copyright (C) 2012  Neop (aka moemneop, email: mneop@web.de)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "fileio.h"

/// liest eine Textdatei in einen String ein
string readfile(string filename){
    stringstream ret;
    ifstream file(filename.c_str());
    if(!file.is_open()){
        cerr << "Could not open file " << filename << endl;
        return "";
    }
    ret << file.rdbuf();
    string ret2 = ret.str();
    file.close();
    return ret2;
}

/// liest eine Textdatei in einen Stringvektor ein
vector<string> readfile_sv(string filename, bool rs){
    ifstream file(filename.c_str());
    vector<string> ret;
    if(!file.is_open()){
        cerr << "Could not open file " << filename << endl;
        return ret;
    }
    char line[readfile_line_length];
    while(!file.eof()){
        file.getline(line, readfile_line_length);
        string linestr = string(line);
        if(rs)
            if(linestr == "") continue;
            while(linestr[0] == ' '){ // Leerzeichen am Anfang der Zeile entfernen
            linestr = linestr.substr(1, linestr.size() - 1);
        }
        ret.push_back(linestr);
    }
    return ret;
}

bool config_comp(string line, string key){
    return (line.compare(0, key.length(), key) == 0) ? true : false;
}
